package org.jeecg.modules.InveotoryCenter.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.InveotoryCenter.entity.InveotoryEntity;
import org.jeecg.modules.InveotoryCenter.entity.piciEntity;
import org.jeecg.modules.InveotoryCenter.mapper.InveotoryQueryMapper;
import org.jeecg.modules.InveotoryCenter.service.InveotoryQueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;

@Service
public class InveotoryQueryServiceImpl implements InveotoryQueryService {

    @Autowired
    InveotoryQueryMapper mapper;

    /**
     * 库存查询
     * @param page
     * @return
     */
    @Override
    public IPage<InveotoryEntity> getInveotoryQuerylist(Page<InveotoryEntity> page) {

        IPage<InveotoryEntity> pageList=mapper.getInveotoryQuerylist(page);
        if(pageList!=null){
           for(int i=0;i<pageList.getRecords().size();i++){

               if(pageList.getRecords().get(i).getType()==0){
                   HashMap<String,String> map=mapper.getGoodsdetailbyId(page.getRecords().get(i).getGoodsId());
                   pageList.getRecords().get(i).setGoodsCode(map.get("goods_code"));
                   pageList.getRecords().get(i).setSupplierGoodsCode(map.get("supplier_goods_code"));
                   pageList.getRecords().get(i).setGoodsTypeName(map.get("goods_type_name"));
                   pageList.getRecords().get(i).setUnit(map.get("unit"));
               }else {

                   HashMap<String,String> map=mapper.getFabricdetailbyId( Integer.parseInt(page.getRecords().get(i).getGoodsId())  );
                   pageList.getRecords().get(i).setGoodsCode(map.get("fabric_code"));
                   pageList.getRecords().get(i).setSupplierGoodsCode(map.get("gysfabriccode"));
                   pageList.getRecords().get(i).setGoodsTypeName(map.get("goods_type_name"));
                   pageList.getRecords().get(i).setUnit(map.get("unit"));
               }

           }
        }

        return pageList;
    }


    @Override
    public IPage<piciEntity> getpiciListBykucunId(Page<piciEntity> page, String merchandiseInventoryId) {
        return mapper.getpiciListBykucunId(page,merchandiseInventoryId);
    }


    /**
     *查询商品详情
     * @param goodsCode
     * @return
     */
    @Override
    public InveotoryEntity getGoodsDetail(String merchandiseInventoryId) {
        return mapper.getGoodsDetail(merchandiseInventoryId);
    }


    /**
     * 查询面料的详情
     * @param merchandiseInventoryId
     * @return
     */
    @Override
    public InveotoryEntity getFabricDetail(String merchandiseInventoryId) {
        return mapper.getFabricDetail(merchandiseInventoryId);
    }

    //统计一下总数
    @Override
    public String tongjiSum(String merchandiseInventoryId) {
        return mapper.tongjiSum(merchandiseInventoryId);
    }
}
